<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户列表</title>

    <link rel="stylesheet" href="http://cdn.viptool.cn/lib/bootstrap/3.3.5/css/bootstrap.min.css">
    <link href="../../resource/hotui/css/font-awesome.min.css" th:href="@{/resource/hotui/css/font-awesome.min.css}" rel="stylesheet">
    <!-- Morris -->
    <link href="http://cdn.viptool.cn/lib/morris.js/0.4.3/morris.css" rel="stylesheet">
    <link href="http://cdn.viptool.cn/lib/animate.css/2.1.1/animate.min.css" rel="stylesheet">
    <link href="../../resource/hotui/css/style.min-1.0.8.css" th:href="@{/resource/hotui/css/style.min-1.0.8.css}" rel="stylesheet">
    <link href="../../resource/hotui/css/hotui.style.override.css" th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>
    <link href="http://cdn.viptool.cn/lib/switchery/0.8.2/switchery.min.css" rel="stylesheet"/>
    <link href="http://cdn.viptool.cn/lib/bootstrap-daterangepicker/2.1.25/daterangepicker.min.css" rel="stylesheet">
    <link href="../../resource/lib/bootstrap-datepicker/css/bootstrap-datepicker.min.css" th:href="@{/resource/lib/bootstrap-datepicker/css/bootstrap-datepicker.min.css}" rel="stylesheet"/>
    <link href="http://cdn.viptool.cn/lib/awesome-bootstrap-checkbox/0.3.5/awesome-bootstrap-checkbox.min.css"
          rel="stylesheet">

    <style type="text/css">
        .hr-line-dashed {
            margin: 10px 0;
            height: 1px;
            border-top: 1px dashed #e7eaec;
            background-color: #fff;
            color: #fff;
        }

        .city-picker-selector select {

        }

        .daterangepicker {
            z-index: 999999999 !important;
        }

        .nav-tabs input {
            width: 20px;
            height: 23px;
        }
    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight tooltip-demo">
    <!--search-->
    <form role="form" id="searchForm" class="search-panel" method="get" th:object="${condition}">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="form-inline">
                            <input type="hidden" th:value="${pageIndex}" name="pageIndex"/>
                            <input type="hidden" th:value="*{status}"/>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="keyword">关键字：</label>
                                <input type="text" class="form-control input-sm mb10" id="keyword" th:value="*{keyword}" name="keyword" placeholder="手机号/姓名" style="width: 156px;"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="createTimePick">注册时间：</label>
                                <input readonly type="text" class="form-control input-sm mb10 data-range-pick" id="createTimePick" name="createTimePick" start-element="#beginTime" end-element="#endTime" placeholder="开始时间-结束时间" style="width: 377px;"/>
                                <input type="hidden" th:value="*{regBeginTime}" id="beginTime" name="regBeginTime"/>
                                <input type="hidden" th:value="*{regEndTime}" id="endTime" name="regEndTime"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <button type="button" onclick="userHandler.search(1)"
                                        class="btn btn-primary btn-sm m-b-none searchBtn">筛选
                                </button>
                                <button type="button" onclick="userHandler.searchAll()" class="btn btn-primary btn-sm m-b-none">显示全部</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!--search-->

    <!--list-->
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li class="active" th:class="${condition.status==-1?'active':''}">
                            <a th:href="@{/user/list}" href="#tab-2">
                                <!-- <div th:if="${condition.status==-1}" class="checkbox checkbox-primary m-b-none m-t-none" style="display: inline-block;">
                                    <input type="checkbox" name="chkAll" style="cursor: pointer;">
                                    <label></label>
                                </div> -->
                                全部</a>
                        </li>
                        <li th:class="${condition.status==1?'active':''}">
                            <a th:href="@{/user/list(status=1)}">
                                <!-- <div th:if="${condition.status==1}" class="checkbox checkbox-primary m-b-none m-t-none" style="display: inline-block;">
                                    <input type="checkbox" name="chkAll" style="cursor: pointer;">
                                    <label></label>
                                </div> -->
                                激活</a>
                        </li>
                        <li th:class="${condition.status==0?'active':''}">
                            <a th:href="@{/user/list(status=0)}">
                                <!-- <div th:if="${condition.status==0}" class="checkbox checkbox-primary m-b-none m-t-none" style="display: inline-block;">
                                    <input type="checkbox" name="chkAll" style="cursor: pointer;">
                                    <label></label>
                                </div> -->
                                禁用</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="panel-body">
                                <!--<div class="form-inline" style="padding-bottom: 15px;text-align: right;">-->
                                <!--<button type="button" onclick="userHandler.register()"-->
                                <!--class="btn btn-primary btn-sm m-b-none">添加白名单用户-->
                                <!--</button>-->
                                <!--</div>-->
                                <table class="table table-bordered table-hover table-center" th:each="user:${users}">
                                    <thead>
                                    <tr>
                                        <th colspan="12" style="color: #636e7b; padding-bottom: 0px; text-align: left;">
                                            <!-- <div class="checkbox checkbox-default m-b-none m-t-none"
                                                 style="display: inline-block;">
                                                <input th:id="${'chk'+user.userId}" th:value="${user.userId}"
                                                       style="margin-top: 0px; cursor: pointer;" type="checkbox"
                                                       name="chkUser" value="560946"/>
                                                <label th:for="${'chk'+user.userId}"></label></div> -->
                                            <span th:text="${user.username}">刘渠成</span>
                                            &nbsp;
                                            <span class="color-primary" th:class="${user.statusClass()}" th:text="${user.status.desc}">激活</span>
                                            <p style="float: right;">
                                                <span class="glyphicon glyphicon-time" data-placement="top" data-toggle="tooltip" data-original-title="注册时间"></span>：<span th:text="${#temporals.format(user.regTime,'yyyy-MM-dd HH:mm:ss')}"></span>
                                            </p>
                                        </th>
                                    </tr>
                                    </thead>
                                    <tr>
                                        <td>姓名</td>
                                        <td>账户/手机</td>
                                        <td>余额</td>
                                        <!--<td>可提余额</td>-->
                                        <td>状态</td>
                                        <!--<td>可否提现</td>-->
                                        <td>操作</td>
                                    </tr>
                                    <tr>
                                        <td th:text="${user.realName}"></td>
                                        <td>
                                            <span th:text="${user.username}">17678767675</span>
                                        </td>
                                        <td>
                                            ￥<span th:text="${user.getTotalBalance()}">100.50</span>
                                        </td>
                                        <td>
                                            <input th:onchange="|userHandler.setDisabled(this,${user.userId})|" onchange="userHandler.setDisabled(this,1)" type="checkbox" class="js-switch" th:checked="${user.status.code}" checked/>
                                        </td>
                                        <!--<td>-->
                                        <!--<input th:onchange="|userHandler.enableWithdrawal(this,${user.userId})|" onchange="userHandler.enableWithdrawal(this,1)" type="checkbox" class="js-switch" th:checked="${user.enableWithdrawal}" checked/>-->
                                        <!--</td>-->
                                        <td>
                                            <button th:onclick="userHandler.userDetail([[${user.userId}]],[[${user.username}]])" type="button"
                                                    class="btn btn-info btn-xs m-b-none">详情
                                            </button>
                                            <button onclick="userHandler.setPassword(1)" th:onclick="|userHandler.setPassword(${user.userId})|" type="button"
                                                    class="btn btn-info btn-xs m-b-none">设置密码
                                            </button>
                                        </td>
                                    </tr>
                                    <thead>
                                    <tr>
                                        <th colspan="12" style="color: #636e7b; padding-bottom: 0px; text-align: left;">
                                            <p style="float: left;" th:text="'注册方式：'+${user.registerType.desc}"></p>
                                            <p style="float: right;">
                                            </p>
                                        </th>
                                    </tr>
                                    </thead>
                                </table>
                                <p style="float: left; margin: 20px 0;">
                                    共<span th:text="${totalRecords}"></span>条记录，当前第<span th:text="${pageIndex}"></span>/<span th:text="${totalPages==0?1:totalPages}"></span>，每页20条记录
                                </p>
                                <ul style="float: right;" class="pagination pagination-split">
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="wallet_modify_modal" class="modal-content-tag">
    <form>
        <input type="hidden" id="wallet_user_id"/>
        <input type="hidden" id="wallet_modify_type"/>
        <div class="form-horizontal" style="width: 479px;">
            <div class="form-group form-inline">
                <label class="col-sm-3 control-label">*修改额度：</label>
                <div class="col-sm-9">
                    <input type="text" required name="wallet_amount" id="wallet_amount" class="form-control input-sm input-s only-float" placeholder="修改额度"/>
                    <br/>
                    <p class="form-control-static color-notice">减少请输入负数</p>
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group">
                <label class="col-sm-3 control-label">*备注：</label>
                <div class="col-sm-9">
                    <textarea placeholder="备注" name="wallet_remark" id="wallet_remark" class="form-control"
                              rows="5" style="height: 100px;width: 300px;"></textarea>
                </div>
            </div>
        </div>
    </form>
</div>

<div id="set_password_modal" class="modal-content-tag">
    <form id="passwordForm">
        <input type="hidden" id="password_user_id"/>
        <div class="form-horizontal" style="width: 479px;">
            <div class="form-group form-inline">
                <label class="col-sm-3 control-label">*设置密码：</label>
                <div class="col-sm-9">
                    <input type="password" required name="password" id="password" class="form-control input-sm input-s" placeholder="设置密码"/>
                    <br/>
                </div>
            </div>
            <div class="form-group form-inline">
                <label class="col-sm-3 control-label">*确认密码：</label>
                <div class="col-sm-9">
                    <input type="password" required equalTo="#password" name="confirmPwd" id="confirmPwd" class="form-control input-sm input-s" placeholder="确认密码"/>
                    <br/>
                </div>
            </div>
        </div>
    </form>
</div>

<!--基础框架js-->
<script src="http://cdn.viptool.cn/lib/jquery/2.2.4/jquery.min.js"></script>
<script src="http://cdn.viptool.cn/lib/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316" th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316?1234567" th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316(123)}"></script>
<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>

<script src="http://cdn.viptool.cn/lib/moment.js/2.19.2/moment.min.js"></script>
<script src="../../resource/hotui/js/plugins/datetimepick/js/daterangepicker.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/daterangepicker.js}"></script>

<script src="../../resource/lib/bootstrap-datepicker/js/bootstrap-datepicker.min.js"
        th:src="@{/resource/lib/bootstrap-datepicker/js/bootstrap-datepicker.min.js}"></script>
<script src="../../resource/lib/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.min.js"
        th:src="@{/resource/lib/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.min.js}"></script>

<script src="http://cdn.viptool.cn/lib/switchery/0.8.2/switchery.min.js"></script>

<script src="http://cdn.viptool.cn/lib/jquery-validate/1.17.0/jquery.validate.min.js"></script>
<script src="http://cdn.viptool.cn/lib/jquery-validate/1.17.0/localization/messages_zh.min.js"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-validate.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-validate.js}"></script>

<script type="text/javascript" th:inline="javascript">
    const pageIndex = /*[[${pageIndex}]]*/  1;
    const totalPages = /*[[${totalPages}]]*/  0;
    const pageUri = /*[[@{/user/list}]]*/  "";
    const userApiBase = /*[[@{/user}]]*/  "/user";
    const userDetailUri = /*[[@{/user/detail}]]*/  "user_detail.html";
</script>

<script>
    var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));

    elems.forEach(function (html) {
        var switchery = new Switchery(html, {size: 'small'});
    });

    let setPasswdModal = $("#set_password_modal").modal("设置密码", function () {
        $("#passwordForm").submit();
    });

    $(function () {
        //初始化分页
        var pageinate = new hot.paging(".pagination", pageIndex, totalPages, 7);

        pageinate.init(function (p) {
            userHandler.search(p);
        });
        $(document).keyup(function (event) {
            if (event.keyCode == 13) {
                $(".searchBtn").trigger("click");
            }
        });

        $("input[name=chkAll]").change(function () {
            if ($(this).prop("checked")) {
                $("input[name=chkUser]").prop("checked", "checked");
            } else {
                $("input[name=chkUser]").removeAttr("checked");
            }
        });
        userHandler.init();
    });

    var userHandler = {
        init: function () {
        },
        search: function (pageIndex) {
            $("input[name=pageIndex]").val(pageIndex);
            $("#searchForm").submit();
        },
        searchAll: function () {
            window.location.href = pageUri;
        },
        setDisabled: function (obj, userId) {
            let currentStatus = obj.checked;
            hot.ajax("setDisabled", {
                userId: userId,
                agentDisabled: !currentStatus
            }, function (apiResult) {
                if (apiResult.resultCode !== 2000) {
                    hot.tip.error("操作失败--" + apiResult.resultMsg, function () {
                        window.location.reload();
                    });
                }
            }, function () {
            }, "post");
        },
        enableWithdrawal: function (obj, userId) {
            let currentStatus = obj.checked;
            hot.ajax("enableWithdrawal", {
                userId: userId,
                enableWithdrawal: currentStatus
            }, function (apiResult) {
                if (apiResult.resultCode !== 2000) {
                    hot.tip.error('操作失败--' + apiResult.resultMsg, function () {
                        window.location.reload();
                    })
                }
            }, function () {
            }, "post");
        },
        setPassword: function (userId) {
            setPasswdModal.show(function () {
                $("#password_user_id").val(userId);
                $("#passwordForm").validateCallback(function () {
                    let password = $("#password").val();
                    let requestData = {
                        userId: userId,
                        password: password
                    };

                    hot.ajax(userApiBase + "/setPassword", requestData, function (apiResult) {
                        if (apiResult.resultCode === 2000) {
                            setPasswdModal.hide(function () {
                                hot.tip.success("设置成功");
                            });
                        } else {
                            hot.tip.error("设置失败--" + apiResult.resultMsg);
                        }
                    }, function () {
                    }, "post", 300);
                })
            });
        },
        userDetail: function (userId, realName) {
            var url = userDetailUri + "?userId=" + userId;
            hot.newTab(url, realName);
        }
    };
</script>
</body>
</html>
